PATHMac OS 8 and 9 Developer Documentation > Interapplication Communication > AppleScript for Scripters >

AppleScript Language Guide

   

Record

A value of class Record is an unordered collection of properties. Like the properties of application objects, each property has a label, and the properties of a record are distinguished from each other by their label. There can be only one property with a particular label in any record.

LITERAL EXPRESSIONS

Records appear in scripts as series of properties contained within braces and separated by commas. Each property has a label. Following the label is a colon, and following the colon, the value of the property. For example, the record

{ name:"Steve", height:74.5, weight:175 }

contains three properties: Name (a string), Height (a real number), and Weight (an integer). The values assigned to properties can belong to any class.

AppleScript evaluates expressions in a record before using the record in other expressions. For example, the following record is equivalent to the previous one.

{ name:"Steve", height:76 - 1.5, weight:150 + 25 }
PROPERTIES

In addition to the properties that are specific to each record, two properties are common to all records:

Class
The class identifier for the object. For most records, the value of the Class property is record .
The Class property of a record can be modified--it is not read-only. For example, an application that edits text could define a special record to specify the styles (such as bold and underline ) of text objects. The value of the Class property for these records, as illustrated in the following example, is the class identifier Text Style Info.
tell application "AppleWorks"
    -- Get text style from open document.
    style of text body of document 1
end tell

Running the previous script produces the following result:

{class:text style info, on styles:{plain}, off styles:{italic, underline,
outline, shadow, condensed, expanded, strikethrough, superscript, subscript,
superior, inferior, double underline}}
Length
An integer containing the number of properties in the record. This property is read-only.

If you define a Class property explicitly in a record, the value you define replaces the implicit Class property record described above.

OPERATORS

The operators that can have records as operands are & , = , , Contains, and Is Contained By.

For detailed explanations and examples of how AppleScript operators treat records, see Operators That Handle Operands of Various Classes.

COMMANDS HANDLED

You can count the properties in a record with the Count command. For example, the value of the following statement is 2 .

count {name:"Robin", mileage:4000}
--result: 2

Another way to count the properties in a record is with a Length property reference. For example, the value of the following reference is 3 .

length of {name:"Robin", mileage:8000, city:"Sunnyvale"}
--result: 3
REFERENCE FORMS

The only reference form you can use with records is the Property reference form. For example, the following reference specifies the Mileage property of a record.

mileage of {name:"Robin", mileage:8000, city:"Sunnyvale"}
--result: 8000

You cannot refer to properties in records by numeric index. For example, the following reference, which uses the Index reference form on a record, is not valid.

item 2 of { name:"Robin", mileage:8000, city:"Sunnyvale" }
--result: not a valid reference
COERCIONS SUPPORTED

AppleScript supports coercion of records to lists; however, all property labels are lost in the coercion and the resulting list cannot be coerced back to a record.

NOTES

To specify a particular property of a record, you give its name. For example, if you assign the record to a variable, as in

copy { name:"Steve", height:70.5, weight:165 } to writer

you can then get the value of the Name property with the expression

name of writer --result: "Steve"

A property of a record can contain a value of any class. You can change the class of a property simply by assigning a value belonging to another class.

After you define a record, you cannot add additional properties to it. You can, however, concatenate records. For more information, see Concatenation.


© 1999 Apple Computer, Inc. – (Last Updated 21 May 99)